package com.ebupt.common.net.ktx

import com.ebupt.common.net.model.DataResult
import retrofit2.Call
import retrofit2.await
import java.lang.RuntimeException



suspend fun <T:Any>Call<T>.serverData():DataResult<T>{
    var result: DataResult<T> = DataResult.Loading

    kotlin.runCatching {
        this.await()
    }.onSuccess {
        result = DataResult.Success(it)
    }.onFailure {
        result = DataResult.Error(RuntimeException(it))
        it.printStackTrace()
    }

    return result
}